package com.legna.mhxy.support.service;

import com.legna.mhxy.support.dao.RingCategoryDao;
import com.legna.mhxy.support.dao.RingTypeDao;
import com.legna.mhxy.support.dao.UserRingDao;
import com.legna.mhxy.support.entity.RingType;
import com.legna.mhxy.support.vo.UserRingVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@AllArgsConstructor
public class UserRingService {
    private final RingCategoryDao ringCategoryDao;
    private final RingTypeService ringTypeService;
    private final UserRingDao userRingDao;


    /**
     * 查询用户环
     * @param userId
     * @return
     */
    public List<UserRingVO> getUserRings(Long userId,Long categoryId,Integer categoryType, Integer grade){
        List<RingType> ringTypes = ringTypeService.listAll(categoryId, categoryType, grade);
        List<Long> typeIds = ringTypes.stream().map(RingType::getId).collect(Collectors.toList());
        return userRingDao.selectUserRingDetails(userId,typeIds);
    }

    public UserRingVO getUserRing(Long id) {
        return userRingDao.selectUserRingDetail(id);
    }
}
